#include <iostream>
#include <vector>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

void SubFindPathSum(TreeNode *root, int sum, vector<int> &path, vector<vector<int> > &res){
    if(!root)
        return;

    // leaf
    if(!root->left && !root->right){
        if(root->val == sum){
            path.push_back(root->val);
            res.push_back(path);
            path.pop_back();
            return;
        }
        else
        {
            return;
        }
    }

    // not leaf
    path.push_back(root->val);
    if(root->left){
        SubFindPathSum(root->left, sum - root->val, path, res);
    }
    if(root->right){
        SubFindPathSum(root->right, sum - root->val, path, res);
    }
    path.pop_back();
    return;
}

vector<vector<int> > pathSum(TreeNode *root, int sum) {
    // Start typing your C/C++ solution below
    // DO NOT write int main() function
    vector<vector<int> > res;
    vector<int> path;
    SubFindPathSum(root, sum, path, res);
    return res;
}



int main(){
    return 0;
}